package com.teacold.customdemo.chapter_eight;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.teacold.customdemo.R;

public class LightBookView extends View {
    private Paint mBitpaint;
    private Bitmap mBmpDst,mBmpSrc;

    public LightBookView(Context context) {
        this(context,null);
        }

    public LightBookView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LightBookView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mBitpaint=new Paint();
        mBmpDst=BitmapFactory.decodeResource(getResources(), R.drawable.one,null);
        mBmpSrc=BitmapFactory.decodeResource(getResources(), R.drawable.two,null);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int layerId=canvas.saveLayer(0,0,getWidth(),getHeight(),null,Canvas.ALL_SAVE_FLAG);
        canvas.drawBitmap(mBmpDst,0,0,mBitpaint);
         mBitpaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY));
         canvas.drawBitmap(mBmpSrc,0,0,mBitpaint);
         mBitpaint.setXfermode(null);
         canvas.restoreToCount(layerId);
    }
}
